package com.yss.reportworld.controller;

import com.alibaba.fastjson.JSON;
import com.yss.common.core.web.controller.BaseController;
import com.yss.common.core.web.domain.AjaxResult;
import com.yss.common.logger.annotation.Log;
import com.yss.common.logger.enums.BusinessType;
import com.yss.common.security.annotation.Logical;
import com.yss.common.security.annotation.RequiresPermissions;
import com.yss.reportworld.domain.Database;
import com.yss.reportworld.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 数据对比Controller
 *
 * @author yss
 * @date 2023-03-29
 */
@RestController
@RequestMapping("/compareData")
public class CompareDataController extends BaseController {
    @Autowired
    private ICompareDataService compareDataService;
    @Autowired
    private IModularService modularService;
    @Autowired
    private ICustomerService customerService;
    @Autowired
    private IReportService reportService;

    /**
     * 查询历史数据和当前数据
     */
    @RequiresPermissions(value = {"reportworld:database:data:comparedata","reportworld:detail:data:comparedata","reportworld:table:data:comparedata","reportworld:datasql:data:comparedata"},logical = Logical.OR)
    @PostMapping("/list")
    public AjaxResult list(@RequestBody String queryJson) {
        AjaxResult ajax = AjaxResult.success();
        Map<String, String> mapType = JSON.parseObject(queryJson, LinkedHashMap.class);
        ajax.put("formList", compareDataService.queryCompareDataColum(mapType.get("dataCode")));
        ajax.put("rows", compareDataService.queryCompareData(mapType.get("dataCode"), mapType.get("dataId")));

        //加载所属模块，客户，报表
        ajax.put("modularTree", modularService.selectModularTreeList());
        ajax.put("customerTree", customerService.selectCustomerTreeList());
        ajax.put("reportTree", reportService.selectReportTreeList());
        return ajax;
    }
}
